#include<scheme.h>
#include<scheme-private.h>
#include<dynload.h>
#include<windows.h>
#include<string.h>
#include<winsock2.h>

#define DLLIMPORT __declspec (dllexport)

DLLIMPORT void init_servlet (scheme* sc);
//extern void  addFuncsSERVLET(scheme *sc) ;
extern void  init_servlet(scheme *sc);

//typedef struct mg_connection mg_conn;

static pointer smg_print(scheme *sc, pointer args){
	SOCKET* conn ;
	long v = 0;
	char* s;
	if(args!=sc->NIL) {
               if(is_number(pair_car(args))) {
                    v=ivalue(pair_car(args));
                    conn = (SOCKET*)v;
                    s = string_value(pair_car(pair_cdr(args)));
                    send(*conn,s,strlen(s),0);
               }
           }
           return sc->NIL;
          }

void init_servlet(scheme* sc){
	scheme_define (sc, sc->global_env,
                   mk_symbol (sc, "mg_print"),
                   mk_foreign_func (sc, smg_print)) ;
                   return;
   /*sc->interface->scheme_define(
   sc,sc->global_env,
   sc->interface->mk_symbol(sc,"mg_print"),
   sc->interface->mk_foreign_func(sc,smg_print)); 
   return; */
}
/*
void addFuncsSERVLET(scheme* sc){
   scheme_define (sc, sc->global_env,
                   mk_symbol (sc, "mg_print"),
                   mk_foreign_func (sc, smg_print)) ;
                   return; 
}
*/

